package com.alvin.demo.common.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一返回类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
	private Integer code;
	private String msg;
	private Object data;

	public static Result ok(Object data) {
		if (data instanceof String) {
			return new Result(200, data.toString(), null);
		}
		return new Result(200, "操作成功!!", data);
	}

	public static Result ok(String message, Object data) {
		return new Result(200, message, data);
	}

	public static Result ok() {
		return Result.ok(null);
	}

	public static Result error(String message) {
		return new Result(201, message, null);
	}
	public static Result error(Integer code ,String message) {
		return new Result(code, message, null);
	}
}